<template>
  <!-- 这种选农业类型不用重复写样式 -->
  <div class="farmtypeview">
    <!-- 农业类型 -->
    <div class="select-farmtype">
      <div
        v-for="(item, index) in basefarmtype"
        :key="index"
        class="farmtypebutton"
        :class="
          item.virtualSystemNo === nowselectmessage.virtualSystemNo
            ? 'farmtypebutton-active'
            : ''
        "
        @click="slecttype(item)"
      >
        <div class="but-line">
          {{ item.virtualSystemName }}
        </div>
      </div>
      <span style="font-size: 20px;white-space: nowrap;">当前基地：{{ organizationName }}</span>
    </div>
    <!-- 框框 -->
    <div class="select-border">
      <slot name="farmtypemain" :typename="nowselectmessage"> </slot>
    </div>
  </div>
</template>
<script>
import { getToken } from '@/utils/auth'
import axios from 'axios';
export default {
  name: "SelectFarmType",
  data() {
    return {
      basefarmtype: [
        // {
        //   "description": "大田种植",
        //   "farmingTypeNo": 1,
        //   "farmingTypeName": "大田种植"
        // },
        // {
        //   "description": "大棚种植",
        //   "farmingTypeNo": 2,
        //   "farmingTypeName": "大棚种植"
        // },
        // {
        //   "description": "畜牧养殖",
        //   "farmingTypeNo": 3,
        //   "farmingTypeName": "畜牧养殖"
        // },
        // {
        //   "description": "水产养殖",
        //   "farmingTypeNo": 4,
        //   "farmingTypeName": "水产养殖"
        // },
        // {
        //   "description": "工厂养鱼",
        //   "farmingTypeNo": 5,
        //   "farmingTypeName": "工厂养鱼"
        // }
      ],
      nowselectmessage: { description: "大田种植", farmingTypeNo: 1 },
      organizationNo: '',
      organizationName: '',
      databaseName: ''
    };
  },
  created() {
    this.organizationNo = getToken('organizationBaseNo')
    this.organizationName = getToken('organizationBaseName')
    this.databaseName = getToken('databaseName')
  },
  mounted() {
    this.getallfarmlist()
  },
  methods: {
    // 获取所有农业类型
    getallfarmlist() {
      axios({
        method: "post",
        url: this.$webSerUrlPro + "config/virtualSystem/queryByCondition",
        headers: {
          databaseName: this.databaseName
        },
        data: {
          organizationNo: this.organizationNo
        },
        params: {}
      }).then(response => {
        let farmmes = response.data.data
        if (farmmes && farmmes[0]) {
          this.basefarmtype = farmmes
          this.slecttype(farmmes[0])
        }
      })
    },
    slecttype(e) {
      this.nowselectmessage = e;
      this.$emit("farmtypemessage", e);
    }
  }
};
</script>
<style lang="scss" scoped>
    @import "~@/styles/variables.scss";
.farmtypeview {
  width: 100%;
  height: 100%;
  // background-color: antiquewhite;
  .select-farmtype {
    width: 100%;
    height: 50px;
    overflow: hidden;
    display: flex;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    &:first-of-type {
      margin-left: 15px;
    }
    &:last-of-type {
      margin-right: 15px;
    }
 .farmtypebutton {
      width: 159px;
      min-width: 159px;
      height: 40px;
      background: #00525D;
      border-radius: 48px 48px 48px 48px;
      opacity: 1;
      // border: 1px solid #005b5f;
      display: flex;
      justify-content: center;
      align-items: center;
      cursor: pointer;
      margin-right: 12px;
      .but-line {
        width: 100%;
        height: 28px;
        text-align: center;
        font-size: 20px;
        font-family: PingFang SC-Regular, PingFang SC;
        font-weight: 400;
        color: $textColor;
        line-height: 28px;
      }

    }
    .farmtypebutton-active {
        background: #009fa5;
    }
    .farmtypebutton:hover{
    background: #009fa5;
    }
  }
  .select-border {
    margin-top: -30px;
    width: 100%;
    height: calc(100% - 20px);
    // border: 2px dashed #01444e;
    padding: 40px 10px;
  }
}
::v-deep {
  .el-dialog {
        width: 20%;
        height: 30vh;
        min-width: 30%;
        .el-dialog__body {
          height: 18vh;
        }
      }
}
</style>
